package b1.scenes
{
	import b1.net.*;
	
	import com.greensock.*;
	
	import flash.display.Sprite;
	import flash.text.*;

	public class ArrowHelper extends Sprite
	{
		//0 上 1 下 2 左 3 右
		private var direction:int;
		private var text:TextField;
		private var arrowImg:Sprite;
		private var paneImg:Sprite;
		
		public function ArrowHelper(directions:int, words:String, wordWidth:int, wordHeight:int)
		{
			super();
			text = new TextField();
			direction = directions;
			var UpArrow:Class = ResourceHelper.getInstance().getClassByName("NewHelperArrow");
			var WordPane:Class = ResourceHelper.getInstance().getClassByName("NewHelperPane");
			arrowImg = new UpArrow();
			paneImg = new WordPane();

			text.selectable = false;
			text.defaultTextFormat = new TextFormat("微软雅黑", 20, 0x000000);
			text.wordWrap = true;
			text.width = wordWidth;
			text.text = words;
			var arrowX:int = arrowImg.x;
			var arrowY:int = arrowImg.y;
			if(direction == 0)
			{
				arrowImg.y += arrowImg.height;
				arrowImg.rotation = 270;
				addChild(arrowImg);
				text.x = arrowX + arrowImg.width/2 - wordWidth/2 ;
				text.y = arrowY + arrowImg.height + 10;
				paneImg.x = text.x - 10;
				paneImg.y = text.y - 10;
				paneImg.width = wordWidth + 20;
				paneImg.height = wordHeight +20;
				addChild(paneImg);
				addChild(text);
			}
			else if(direction == 1)
			{
				arrowImg.rotation = 90;
				arrowImg.x += arrowImg.width;
				addChild(arrowImg);
				text.x = arrowX + arrowImg.width/2 - wordWidth/2;
				text.y = arrowY - wordHeight - 20;
				paneImg.x = text.x - 10;
				paneImg.y = text.y - 10;
				paneImg.width = wordWidth + 20;
				paneImg.height = wordHeight + 20;
				addChild(paneImg);
				addChild(text);
			}
			else if(direction == 2)
			{
				arrowImg.x += arrowImg.width;
				arrowImg.y += arrowImg.height;
				arrowImg.rotation = 180;
				addChild(arrowImg);
				text.x = arrowX + arrowImg.width + 20;
				text.y = arrowY + arrowImg.height/2 - wordHeight/2;
				paneImg.x = text.x - 10;
				paneImg.y = text.y - 10;
				paneImg.width = wordWidth + 20;
				paneImg.height = wordHeight +20;
				addChild(paneImg);
				addChild(text);
			}
			else if(direction == 3)
			{
				addChild(arrowImg);
				text.x = arrowX - wordWidth - 20;
				text.y = arrowY + arrowImg.height/2 - wordHeight/2;
				paneImg.x = text.x - 10;
				paneImg.y = text.y - 10;
				paneImg.width = wordWidth + 20;
				paneImg.height = wordHeight +20;
				addChild(paneImg);
				addChild(text);
			}
			startMove();
		}
		
		private function startMove():void
		{
			var desX:int;
			var desY:int;
			if(direction == 0)
			{
				desX = arrowImg.x;
				desY = arrowImg.y - 30;
				TweenLite.to(arrowImg,0.45,{x:desX, y:desY,onComplete:backMove});
			}
			else if (direction == 1)
			{
				desX = arrowImg.x;
				desY = arrowImg.y + 30;
				TweenLite.to(arrowImg,0.45,{x:desX, y:desY,onComplete:backMove});
			}
			else if (direction == 2)
			{
				desX = arrowImg.x - 30;
				desY = arrowImg.y ;
				TweenLite.to(arrowImg,0.45,{x:desX, y:desY,onComplete:backMove});
			}
			else if (direction == 3)
			{
				desX = arrowImg.x + 30;
				desY = arrowImg.y ;
				TweenLite.to(arrowImg,0.45,{x:desX, y:desY,onComplete:backMove});
			}
		}
		
		private function backMove():void
		{
			var desX:int;
			var desY:int;
			if(direction == 0)
			{
				desX = arrowImg.x;
				desY = arrowImg.y + 30;
				TweenLite.to(arrowImg,0.45,{x:desX, y:desY,onComplete:startMove});
			}
			else if (direction == 1)
			{
				desX = arrowImg.x;
				desY = arrowImg.y - 30;
				TweenLite.to(arrowImg,0.45,{x:desX, y:desY,onComplete:startMove});
			}
			else if (direction == 2)
			{
				desX = arrowImg.x + 30;
				desY = arrowImg.y ;
				TweenLite.to(arrowImg,0.45,{x:desX, y:desY,onComplete:startMove});
			}
			else if (direction == 3)
			{
				desX = arrowImg.x - 30;
				desY = arrowImg.y ;
				TweenLite.to(arrowImg,0.45,{x:desX, y:desY,onComplete:startMove});
			}
		}

	}
}